package com.software_product_construction.backend_software_product_construction.controller;

import com.software_product_construction.backend_software_product_construction.pojo.Lessee;
import com.software_product_construction.backend_software_product_construction.pojo.User;
import com.software_product_construction.backend_software_product_construction.service.impl.LesseeServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.lang.management.BufferPoolMXBean;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping(value = "/lessee")
public class LesseeController {

    @Autowired
    private LesseeServiceImpl lesseeService;

    @GetMapping("/getUserList")
    public List<User> getUserList(@RequestParam("lesseeId") String lesseeId, @RequestParam("nickName")String nickName, @RequestParam("from")Integer from, @RequestParam("to")Integer to){
        List<User> users = lesseeService.getUserList(lesseeId,nickName,from,to);
        return users;
    }

    @GetMapping("/deleteUserById")
    public Boolean deleteUserById(@RequestParam("id")String id){
        return lesseeService.deleteUserById(id);
    }

    @PostMapping("/modifyUserInfo")
    public Boolean modifyUserInfo(@RequestBody Map<String,Object> map){
        String id = (String) map.get("id");
        String password = (String)map.get("password");
        String nickname = (String) map.get("nickname");
        Integer sex = (Integer) map.get("sex");
        return lesseeService.modifyUserInfo(id,password,nickname,sex);
    }

    @PostMapping("/modifyPersonalInfo")
    public Boolean modifyPersonalInfo(@RequestBody Map<String,Object> map){
        return lesseeService.modify(map)==1?true:false;
    }

    @GetMapping("/getLesseePersonalHistory")
    public List<Lessee> getLesseePersonalHistory( @RequestParam("from")Integer from, @RequestParam("to")Integer to,@RequestParam("lesseeId") String lesseeId){
        return lesseeService.getLesseePersonalHistory(from,to,lesseeId);
    }



}
